import Axios from './core/Axios.js';
import defaultConfig from './core/defaultConfig.js';
import getCancelAndToken from './cancel/index.js';

function createInstance(defaultConfig) {
  const context = new Axios(defaultConfig);

  const instance = Axios.prototype.request.bind(context);

  // 让axios拿到实例的属性

  instance.defaults = context.defaults;
  instance.interceptor = context.interceptor;

  // 为axios扩展方法

  instance.get = context.get;

  return instance;
}

const axios = createInstance(defaultConfig);

axios.getCancelAndToken = getCancelAndToken;

export default axios;
